
clear
do "...\First.do"
********************************************************************************
use "$work\analysis_sample.dta"
keep if inrange(age,40,70)


g help=1 if inrange(timing,-4,0)
bys pnr: egen N_pre_2=total(help)
tab N_pre_2

keep if N_pre_2==5



********************************************************************************
* TABLE D3
********************************************************************************
replace post=1 if timing==0

g pre_statins=(statins==1 & post==0)
g pre_diabetes=((diabetes_control==1 | metformin==1) & post==0)
g pre_copd=((ACSC_COPD==1 | COPD_med==1) & post==0)

foreach var of varlist pre_statins pre_diabetes pre_copd {
	
 bys pnr: egen d_`var'=max(`var')
	drop `var'
	
}


label var d_pre_statins "Pre CVC"
label var d_pre_diabetes "Pre diabetic"
label var d_pre_copd "Pre COPD"


********************************************************************************

global gp_X "mean_age mean_male mean_dk ku au sdu other i.N_doctors "
global patient_X "male i.age non_dk married low_ses"


areg help3 d_pre_statins d_pre_diabetes d_pre_copd $patient_X $gp_X if timing==1 & low_ses==0, a(gp_fe) cluster(ydernr)
test d_pre_statins d_pre_diabetes d_pre_copd male non_dk married
test d_pre_statins d_pre_diabetes d_pre_copd

outreg2 using "$table\selecetion_patient_X.doc", replace keep(male age non_dk married low_ses d_pre_statins d_pre_diabetes d_pre_copd) sortvar(male non_dk married d_pre_statins d_pre_diabetes d_pre_copd) tex label bdec(5) sdec(5) rdec(5) ctitle(High SES)



areg help3 d_pre_statins d_pre_diabetes d_pre_copd $patient_X $gp_X if timing==1 & low_ses==1, a(gp_fe) cluster(ydernr)
test d_pre_statins d_pre_diabetes d_pre_copd male non_dk married
test d_pre_statins d_pre_diabetes d_pre_copd

outreg2 using "$table\selecetion_patient_X.doc", append keep(male age non_dk married low_ses d_pre_statins d_pre_diabetes d_pre_copd) tex label bdec(5) sdec(5) rdec(5) ctitle(Low SES)



areg help3 d_pre_statins d_pre_diabetes d_pre_copd $patient_X $gp_X if timing==1 & _known_new2==1 & low_ses==0, a(gp_fe) cluster(ydernr)
test d_pre_statins d_pre_diabetes d_pre_copd male non_dk married
test d_pre_statins d_pre_diabetes d_pre_copd

outreg2 using "$table\selecetion_patient_X.doc", append keep(male age non_dk married low_ses d_pre_statins d_pre_diabetes d_pre_copd) tex label bdec(5) sdec(5) rdec(5) ctitle(High SES)


areg help3 d_pre_statins d_pre_diabetes d_pre_copd $patient_X $gp_X if timing==1 & _known_new2==1 & low_ses==1, a(gp_fe) cluster(ydernr)
test d_pre_statins d_pre_diabetes d_pre_copd male non_dk married
test d_pre_statins d_pre_diabetes d_pre_copd

outreg2 using "$table\selecetion_patient_X.doc", append keep(male age non_dk married low_ses d_pre_statins d_pre_diabetes d_pre_copd) tex label bdec(5) sdec(5) rdec(5) ctitle(Low SES)



